package cn.wolfcode.controller;


import cn.wolfcode.domain.JsonResult;
import cn.wolfcode.domain.MessageBoard;
import cn.wolfcode.service.IMessageBoardService;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.ISystemDictionaryItemService;
import cn.wolfcode.util.RequiredPermission;
import cn.wolfcode.util.UserContext;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/messageBoard")
public class MessageBoardController {

    @Autowired
    private IMessageBoardService messageBoardService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo<MessageBoard> pageInfo = messageBoardService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("items",systemDictionaryItemService.selectBySn("business") );
        return "messageBoard/list";
    }

    @RequestMapping("/listDetail")
    public String listDetail(Long id,Model model){
        MessageBoard messageBoard = messageBoardService.get(id);
        model.addAttribute("messageBoard", messageBoard);
        return "/messageBoard/listDetail";
    }

    @RequestMapping("/save")
    @ResponseBody
    public JsonResult save(MessageBoard messageBoard){
        messageBoardService.save(messageBoard);
        return new JsonResult();
    }
}
